package com.roubsite.cloud.common.bean;

import com.roubsite.cloud.common.bean.enums.CommonStatusCodeEnum;
import com.roubsite.cloud.common.bean.enums.ResultStatusCode;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author ceshi
 * @date 2021/3/814:54
 * @description: 统一返回封装
 * @version: 1.0.0
 */
public class Result {

    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("消息")
    private String msg;

    @ApiModelProperty("数据")
    private Object data;

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(Object data) {
        this.code = CommonStatusCodeEnum.SUCCESS.getCode();
        this.msg = CommonStatusCodeEnum.SUCCESS.getMsg();
        this.data = data;
    }

    public Result(ResultStatusCode resultStatusCode) {
        this.code = resultStatusCode.getCode();
        this.msg = resultStatusCode.getMsg();
    }

    public static Result setData(Object data) {
        return new Result(data);
    }

    public static Result setResultStatusCode(ResultStatusCode resultStatusCode) {
        return new Result(resultStatusCode);
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }
}